const execSync = require("child_process").execSync;
function setHttpProxy(ip, port) {
  execSync(`networksetup -setwebproxy Wi-Fi ${ip} ${port}`);
}
function setHttpsProxy(ip, port) {
  execSync(`networksetup -setsecurewebproxy Wi-Fi ${ip} ${port}`);
}
function getHttpProxy() {
    let config = {
      enabled: false,
      ip:'',
      port:'',
    };
    const str = execSync(`networksetup -getsecurewebproxy Wi-Fi`).toString();
    const strArr = str.split('\n');
    config.enabled = strArr[0].includes("Enabled: Yes");
    config.ip = strArr[1].replace('Server: ','')
    config.port = strArr[2].replace('Port: ','')
  
    console.log(config);
    return config;
  }
function getHttpsProxy() {
  let config = {
    enabled: false,
    ip:'',
    port:'',
  };
  const str = execSync(`networksetup -getsecurewebproxy Wi-Fi`).toString();
  const strArr = str.split('\n');
  config.enabled = strArr[0].includes("Enabled: Yes");
  config.ip = strArr[1].replace('Server: ','')
  config.port = strArr[2].replace('Port: ','')

  console.log(config);
  return config;
}
module.exports = {
  setHttpProxy,
  setHttpsProxy,
};

getHttpProxy();
